package com.ushine.web.communication.signature;


import com.ushine.web.communication.signature.annotation.Signature;
import com.ushine.web.communication.signature.annotation.SignatureField;

import javax.validation.constraints.NotBlank;
import java.util.HashSet;
import java.util.Set;

/**
 * @Author: yls
 * @Date: 2021/12/16 16:15
 * @Description: 签名实体类
 * @Version 1.0
 */
@Signature
public class SignatureHeaders {
    public static final String SIGNATURE_HEADERS_PREFIX = "yls-signature";

    public static final Set<String> HEADER_NAME_SET = new HashSet<>();

    public static final String HEADER_APP_ID = SIGNATURE_HEADERS_PREFIX + "-appId";
    public static final String HEADER_TIMESTAMP = SIGNATURE_HEADERS_PREFIX + "-timeStamp";
    public static final String HEADER_NONCE = SIGNATURE_HEADERS_PREFIX + "-nonce";
    public static final String HEADER_SIGNATURE = SIGNATURE_HEADERS_PREFIX + "-signature";
    public static final String HEADER_SECRET_ID = SIGNATURE_HEADERS_PREFIX + "-appSecretId";
    public static final String HEADER_SECRET_KEY = SIGNATURE_HEADERS_PREFIX + "-appSecretKey";

    static {
        HEADER_NAME_SET.add(HEADER_APP_ID);
        HEADER_NAME_SET.add(HEADER_TIMESTAMP);
        HEADER_NAME_SET.add(HEADER_NONCE);
        HEADER_NAME_SET.add(HEADER_SIGNATURE);
        HEADER_NAME_SET.add(HEADER_SECRET_ID);
        HEADER_NAME_SET.add(HEADER_SECRET_KEY);
    }

    /**
     * 线下分配值 【appId】
     */
    @NotBlank(message = "Header中缺少"+HEADER_APP_ID)
    @SignatureField
    private String appId;

    /**
     * 线下分配值 【appSecret】秘钥Id,秘钥对
     */
    @SignatureField
    private String appSecretId;

    /**
     * 线下分配值 【appSecret】秘钥Id,秘钥对
     */
    @SignatureField
    private String appSecretKey;

    /**
     * 流水号【防止重复提交】
     */
//    @NotBlank(message = "Header中缺少"+HEADER_NONCE)
    @SignatureField
    private String nonce;

    /**
     * 时间戳
     */
    @NotBlank(message = "Header中缺少"+HEADER_TIMESTAMP)
    @SignatureField
    private String timeStamp;

    /**
     * 签名
     */
    @NotBlank(message = "Header中缺少"+HEADER_SIGNATURE)
    private String signature;

    public String getAppId() {
        return appId;
    }

    public void setAppId(String appId) {
        this.appId = appId;
    }

    public String getAppSecretId() {
        return appSecretId;
    }

    public void setAppSecretId(String appSecretId) {
        this.appSecretId = appSecretId;
    }

    public String getNonce() {
        return nonce;
    }

    public void setNonce(String nonce) {
        this.nonce = nonce;
    }

    public String getTimeStamp() {
        return timeStamp;
    }

    public void setTimeStamp(String timeStamp) {
        this.timeStamp = timeStamp;
    }

    public String getSignature() {
        return signature;
    }

    public void setSignature(String signature) {
        this.signature = signature;
    }

    public String getAppSecretKey() {
        return appSecretKey;
    }

    public void setAppSecretKey(String appSecretKey) {
        this.appSecretKey = appSecretKey;
    }

    @Override
    public String toString() {
        return "SignatureHeaders{" +
                "appId='" + appId + '\'' +
                ", appSecretId='" + appSecretId + '\'' +
                ", appSecretKey='" + appSecretKey + '\'' +
                ", nonce='" + nonce + '\'' +
                ", timeStamp='" + timeStamp + '\'' +
                ", signature='" + signature + '\'' +
                '}';
    }
}
